package com.example.geoquiz;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.example.geoquiz.databinding.ActivityCheatBinding;

public class CheatActivity extends AppCompatActivity implements BackDialog.OnBtnClickListener{
    public static final String EXTRA_ANSWER_SHOWN = "answer_shown";
    private static final String EXTRA_ANSWER_IS_TRUE = "answer_is_true";
    private ActivityCheatBinding binding;
    private boolean answerIsTrue = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityCheatBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        // 获取传递的值
        answerIsTrue = getIntent().getBooleanExtra(EXTRA_ANSWER_IS_TRUE, false);
        binding.showAnswerButton.setOnClickListener(view -> {
            int answerTextId = answerIsTrue ? R.string.true_button : R.string.false_button;
            binding.answerTextView.setText(answerTextId);
            new BackDialog().show(getSupportFragmentManager(), "返回");
        });
    }

    // 回传给主界面
    public void setAnswerShownResult(boolean isAnswerShown) {
        Intent data = new Intent();
        data.putExtra(EXTRA_ANSWER_SHOWN, isAnswerShown);
        setResult(Activity.RESULT_OK, data);
        finish();
    }
}